using System;
using System.Collections;
using System.Collections.Generic;

public class PDictionary : Dictionary<string, object>
{
	public PDictionary()
	{
	}

	public PDictionary(IDictionary data)
	{
		if (data != null)
		{
			IEnumerator enumerator = data.Keys.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					string key = (string)obj;
					base[key] = data[key];
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
		}
	}

	protected long GetLong(string s)
	{
		long result = 0L;
		if (base.ContainsKey(s))
		{
			long.TryParse(base[s].ToString(), out result);
		}
		return result;
	}

	protected float GetFloat(string s)
	{
		float result = 0f;
		if (base.ContainsKey(s))
		{
			float.TryParse(base[s].ToString(), out result);
		}
		return result;
	}

	protected bool GetBool(string s)
	{
		bool result = false;
		if (base.ContainsKey(s))
		{
			bool.TryParse(base[s].ToString(), out result);
		}
		return result;
	}

	protected int GetInt(string s)
	{
		int result = 0;
		if (base.ContainsKey(s))
		{
			int.TryParse(base[s].ToString(), out result);
		}
		return result;
	}

	protected string GetString(string s)
	{
		return (!base.ContainsKey(s)) ? string.Empty : base[s].ToString();
	}

	protected PDictionary GetDictionary(string s)
	{
		PDictionary pdictionary = new PDictionary();
		if (base.ContainsKey(s) && base[s] is IDictionary)
		{
			Dictionary<string, object> dictionary = (Dictionary<string, object>)base[s];
			foreach (string key in dictionary.Keys)
			{
				pdictionary.Add(key, dictionary[key]);
			}
		}
		return pdictionary;
	}

	protected List<T> GetList<T>(string s)
	{
		List<T> list = null;
		if (base.ContainsKey(s) && base[s] is IList)
		{
			list = new List<T>();
			IEnumerator enumerator = ((IList)base[s]).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					if (obj is T)
					{
						list.Add((T)((object)obj));
					}
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
		}
		return list;
	}

	protected void SetProperty(string key, object value)
	{
		if (base.ContainsKey(key))
		{
			base[key] = value;
		}
		else
		{
			base.Add(key, value);
		}
	}

	public override string ToString()
	{
		return (!base.ContainsKey("name")) ? ("No name field for type: " + base.GetType().ToString()) : base["name"].ToString();
	}
}
